package org.jflame.captcha.creator;

import org.jflame.commons.file.ImageHelper;
import org.jflame.commons.json.JsonHelper;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

public class WordClickImage extends SimpleImage {

    private BufferedImage tipImage;// 正确文字顺序图
    private short clicks;// 需要点击次数

    public WordClickImage(BufferedImage captchaImage, BufferedImage tipImage, short clicks) {
        super(captchaImage);
        this.tipImage = tipImage;
        this.clicks = clicks;
        setOutJson(true);
    }

    public WordClickImage(BufferedImage captchaImage, BufferedImage tipImage, short clicks, String imageFormat) {
        super(captchaImage, imageFormat);
        this.tipImage = tipImage;
        this.clicks = clicks;
        setOutJson(true);
    }

    public short getClicks() {
        return clicks;
    }

    public void setClicks(short clicks) {
        this.clicks = clicks;
    }

    public BufferedImage getTipImage() {
        return tipImage;
    }

    public void setTipImage(BufferedImage tipImage) {
        this.tipImage = tipImage;
    }

    @Override
    public void write(OutputStream out) throws IOException {
        Map<String,Object> displayMap = new HashMap<>();
        displayMap.put("captchaImage", ImageHelper.base64(getCaptchaImage(), getImageFormat()));
        displayMap.put("tipImage", ImageHelper.base64(tipImage, getImageFormat()));
        displayMap.put("clicks", clicks);
        JsonHelper.toJson(displayMap);
    }

}